package restaurant.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingUtilities;

/**
 * This panel displays table usage data.
 * 
 * @author Odessa
 */
@SuppressWarnings("serial")
public class TableDataPanel extends JPanel
{

	/** This panel. */
	JPanel thisPanel = this;

	/** The empty tables text field. */
	private JTextField emptyField;

	/** The empty label. */
	private JLabel emptyLabel;

	/** The occupied tables text field. */
	private JTextField occupiedField;

	/** The occupied label. */
	private JLabel occupiedLabel;

	/** The waiting tables text field. */
	private JTextField waitingField;

	/** The waiting label. */
	private JLabel waitingLabel;

	/** The OK button. */
	private JButton okButton;



	/**
	 * Creates the panel.
	 * 
	 * @param numEmpty the number of empty tables.
	 * @param numOcc the number of occupied tables.
	 * @param numWaiting the number of waiting tables.
	 */
	public TableDataPanel(int numEmpty, int numOcc, int numWaiting) {
		initComponents();

		emptyField.setText(Integer.toString(numEmpty));
		occupiedField.setText(Integer.toString(numOcc));
		waitingField.setText(Integer.toString(numWaiting));
	}



	/**
	 * Initializes the components.
	 */
	private void initComponents()
	{

		emptyLabel = new JLabel();
		emptyField = new JTextField();
		occupiedLabel = new JLabel();
		occupiedField = new JTextField();
		waitingLabel = new JLabel();
		waitingField = new JTextField();
		okButton = new JButton();

		emptyLabel.setText("Number of empty tables");

		emptyField.setColumns(10);

		occupiedLabel.setText("Number of occupied tables");

		occupiedField.setColumns(10);

		waitingLabel.setText("Number of tables waiting on an order");

		waitingField.setColumns(10);

		okButton.setText("OK");
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt)
			{
				okButtonActionPerformed(evt);
			}
		});

		GroupLayout layout = new GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		emptyLabel)
																.addPreferredGap(
																		ComponentPlacement.UNRELATED)
																.addComponent(
																		emptyField,
																		GroupLayout.PREFERRED_SIZE,
																		GroupLayout.DEFAULT_SIZE,
																		GroupLayout.PREFERRED_SIZE))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		occupiedLabel)
																.addPreferredGap(
																		ComponentPlacement.UNRELATED)
																.addComponent(
																		occupiedField,
																		GroupLayout.PREFERRED_SIZE,
																		GroupLayout.DEFAULT_SIZE,
																		GroupLayout.PREFERRED_SIZE))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		waitingLabel)
																.addPreferredGap(
																		ComponentPlacement.UNRELATED)
																.addComponent(
																		waitingField,
																		GroupLayout.PREFERRED_SIZE,
																		GroupLayout.DEFAULT_SIZE,
																		GroupLayout.PREFERRED_SIZE))
												.addComponent(
														okButton,
														Alignment.TRAILING,
														GroupLayout.PREFERRED_SIZE,
														60,
														GroupLayout.PREFERRED_SIZE))
								.addContainerGap(45, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												Alignment.BASELINE)
												.addComponent(emptyLabel)
												.addComponent(
														emptyField,
														GroupLayout.PREFERRED_SIZE,
														GroupLayout.DEFAULT_SIZE,
														GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												Alignment.BASELINE)
												.addComponent(occupiedLabel)
												.addComponent(
														occupiedField,
														GroupLayout.PREFERRED_SIZE,
														GroupLayout.DEFAULT_SIZE,
														GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												Alignment.BASELINE)
												.addComponent(waitingLabel)
												.addComponent(
														waitingField,
														GroupLayout.PREFERRED_SIZE,
														GroupLayout.DEFAULT_SIZE,
														GroupLayout.PREFERRED_SIZE))
								.addGap(34, 34, 34).addComponent(okButton)
								.addContainerGap(42, Short.MAX_VALUE)));

	}



	/**
	 * The event handler for the OK button.
	 * 
	 * @param evt the action event.
	 */
	private void okButtonActionPerformed(ActionEvent evt)
	{
		JFrame frame = (JFrame) SwingUtilities.getRoot(thisPanel);
		frame.dispose();
	}
}
